package com.pengshun.modules.api.news.controller;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.news.service.NewsFlashService;
import com.pengshun.modules.api.news.service.NewsService;
import com.pengshun.modules.api.news.service.dto.NewsDto;
import com.pengshun.modules.api.news.service.dto.NewsFlashDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/1/20
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "快讯管理")
@RequestMapping("/api/flash")
public class NewsFlashController {

    private final NewsFlashService newsFlashService;

    @ApiOperation(value = "快讯保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "标题长度限制20 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "content", value = "内容长度限制500 ", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "type", value = "1快讯2视频3求助 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "images", value = "图片/视频地址 ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "categoryId", value = "区域id ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "cover", value = "封面 ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "categoryName", value = "区域名称 ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "lableName", value = "标签 多个用逗号隔开 ", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    @PostMapping(value = "/save")
    public BaseResult save(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) NewsFlashDto dto) throws Exception {
        dto.setUserId(user.getId());
        BaseResult res = newsFlashService.save(dto);
        return res;

    }
    @ApiOperation(value = "我的列表")
    @GetMapping(value = "/myself")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = " 1待发布/2待审核3已发布4未通过 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页从0开始 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数 ", dataType = "int", required = true, paramType = "query"),
    })
    @Authorization
    public BaseResult myselfList(@ApiIgnore @CurrUserInfo User user,@Validated(value = {Fourth.class})PagePara para)  {
        para.setUserId(user.getId());
        BaseResult res = newsFlashService.myselfList(para);
        return res;

    }
    @ApiOperation(value = "我的快讯详情")
    @GetMapping(value = "/my-detil")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsFlashId", value = " 快讯id ", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult myDetil(@ApiIgnore @Validated(value = {Fourth.class})NewsFlashDto para)  {
        BaseResult res = newsFlashService.myDetil(para.getNewsFlashId());
        return res;

    }
    @ApiOperation(value = "快讯更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsFlashId", value = " 快讯id ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = " 1取消2发布3修改4删除 ", dataType = "int", required = true, paramType = "query"),
    })
    @Authorization
    @PostMapping(value = "/update")
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) NewsFlashDto dto) throws Exception {
        dto.setUserId(user.getId());
        dto.setUserName(user.getName());
        BaseResult res = newsFlashService.update(dto);
        return res;

    }

    @ApiOperation(value = "分类查询")
    @GetMapping(value = "/category")
    public BaseResult category( )  {
        BaseResult res = newsFlashService.category();
        return res;

    }

    @ApiOperation(value = "快讯列表")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = " 0全部1快讯2视频 3求助 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页从0开始 ", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数 ", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult list(@Validated(value = {Fourth.class})PagePara para)  {
        BaseResult res = newsFlashService.list(para);
        return res;

    }

    @ApiOperation(value = "快讯详情")
    @GetMapping(value = "/detil")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "newsFlashId", value = " 快讯id ", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult detil(@Validated(value = {Fourth.class})NewsFlashDto para)  {
        BaseResult res = newsFlashService.detil(para.getNewsFlashId());
        return res;

    }
}
